package cn.hdu.liang.typeinfo;

import java.util.Arrays;
import java.util.List;

abstract class Shape {
    void draw() {
        System.out.println(this + ".draw()");
    }

    public abstract String toString();
}

class Circle extends Shape {

    @Override
    public String toString() {
        return "Circle";
    }
}

class Square extends Shape {

    @Override
    public String toString() {
        return "Square";
    }
}

class Triangle extends Shape {

    @Override
    public String toString() {
        return "Triangle";
    }
}

class Rhomboid extends Shape {

    @Override
    public String toString() {
        return "Rhomboid";
    }
}


public class Shapes {


    public static void main(String[] args) {
        List<Shape> shapeList = Arrays.asList(new Circle(), new Square(), new Triangle(), new Rhomboid());
        for(Shape shape : shapeList) {
            shape.draw();
        }

        //Exam3 Exam4
        for(Shape shape : shapeList) {
            if(shape instanceof Rhomboid) {
                Rhomboid r = (Rhomboid) shape;
                System.out.println(r);
                Circle c = (Circle) shape;
                System.out.println(c);
            }
        }

    }
}
